/*
切片追加与截取 - 截取（类似Python中切片操作）
https://www.bilibili.com/video/BV1gf4y1r79E/?p=14&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

func info(numbers []int) {
	fmt.Printf("len = %d, cap = %d, slice = %v\n", len(numbers), cap(numbers), numbers)
}

func main() {
	// 1. 切片演示
	fmt.Println("切片的截取")
	s := []int{1, 2, 3, 4} // len = 3, cap = 3
	s1 := s[0:1]           // s1还是指向的s
	info(s1)
	s1[0] = 100
	info(s)

	// 2. copy
	s2 := make([]int, 3)
	info(s2)
	copy(s2, s[0:3])
	info(s2)
	s2[0] = 200
	info(s2)
	info(s) // s还是原来的s
}
